A server-side application component can be utilized to encapsulate the business logic of an application. Here the server-side application component can be an instance of a programmable class (also referred to as class), which can be but is not limited to, a Java bean, an Enterprise Java Bean (EJB), an interface, a module, and other suitable concepts, and EJB will be used to illustrate the various embodiments of the invention in the following context. The instances of an EJB are created and managed at runtime by a container, which runs as part of an application server to provide enterprise applications with a high level of abstraction. An EJB can be customized at deployment time via a deployment descriptor, which allows the editing of both the structural and application assembly information about the EJB. An important type of EJB is the entity bean, which is a component that represents an object-oriented view of some entities stored in a persistent storage, such as a database, or entities that are implemented by an existing enterprise application. An EJB query component, such as an EJB Finder, can be deployed in the container to query a database based on a query and receive as the query result, one or more EJB instances containing matched data entities in a database. Here, the database can be a relational database, an Oracle Database, an MS SQL server, a DB2, and other suitable concepts. The query languages utilized by the query can be, but are not limited to, SQL and EJB-QL, wherein EJB-QL is a standard query language that allows queries to be specified against an EJB object without requiring any knowledge of the underlying types of the databases. The query result can be stored in a cache in the container. Here, the cache can be an in-memory storage component enabling fast and easy access to the query result. Once the result of a query is cached, a round-trip access to the database can be spared if the same query is called again later.
In many current web application architectures, only EJB instances of queries using primary keys of data entities in the database can be cached and accessed later. The result of a non-primary key query is often not retrievable from cache, and such query may have to access the database each time it is called. This limits the performance of the application server since non-primary key queries are quite commonly used.